package com.cms.pms.impl;

import com.cms.pms.Store;
import com.cms.pms.Transaction;

public class StoreImpl implements Store<Transaction> {

	Transaction[] transArray = null;

	int capactity = 1 << 13;
	int loss = 1 << 4;

	int head = 0;
	volatile int tail = 0;

	public StoreImpl() {
		transArray = new Transaction[capactity];
	}

	@Override
	public void put(Transaction obj) {
		transArray[head] = obj;
		head = (head + 1) % capactity;
		if (head == tail) {
			tail = (tail + loss) % capactity;
		}
	}

	@Override
	public Transaction take() {
		if (head != tail) {
			Transaction t = transArray[tail];
			transArray[tail] = null;
			tail = (tail + 1) % capactity;
			return t;
		} else
			return null;
	}
}
